<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="templatedraftlist" >
      <el-table-column label="草稿id" align="center" prop="draft_id" />
      <el-table-column label="版本号" align="center" prop="user_version" />
      <el-table-column label="版本描述" align="center" prop="user_desc" />
      <el-table-column label="上传时间" align="center" prop="create_time" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAddtotemplate(scope.row.draft_id,0)"
          >添加普通模板</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleAddtotemplate(scope.row.draft_id,1)"
          >添加标准模板</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {listApplet, getApplet, delApplet, addApplet, updateApplet, changeAppletStatus} from "@/api/wechat/applet";
import {addtotemplate, deletetemplate, gettemplatedraftlist} from "../../../api/wechat/wechat";

export default {
  name: "templatedraft",
  data() {
    return {
      // 遮罩层
      loading: true,
      templatedraftlist: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询小程序商户列表 */
    getList() {
      this.loading = true;
      gettemplatedraftlist().then(response => {
        this.templatedraftlist = response.data.draft_list;
        this.loading = false;
      });
    },
    handleAddtotemplate(draft_id, template_type){
        this.$confirm('是否确认添加草稿ID为"' + draft_id + '"到模板库?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          addtotemplate(draft_id,template_type).then(res =>{
            if(res.data.errcode == 0){
              this.msgSuccess("添加成功");
            }
          })
        }).catch(() => {});


    }
  }
};
</script>
